Comment ça marche :
UI
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)Serveur
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}Et pourtant:
WEBSOCKET
Les websockets :
Les API Rest
Coder une application web avec R et sans {shiny}
Pour la partie front :
Pour la partie backend :
HTML:
<div class="paper container">
<h1>My super web application with R</h1>
<p>Select a Species</p>
<div class="form-group">
<label for="paperSelects1">Species</label>
<select id="paperSelects1">
<option value="versicolor">Versicolor</option>
<option value="setosa">Setosa</option>
<option value="virginica">Virginica</option>
</select>
</div>
<p>Here a space for my ggplot 2</p>
<div id="my_ggplot">
</div>CSS:
JS:
Backend Un express like en R {ambiorix}
app <- Ambiorix$new(port = "3838")
app$get("/species/:id", \(req, res){
res$header("Access-Control-Allow-Origin", "*")
data_slot <- iris %>%
filter(Species == req$params$id)
temp_ <- tempfile(fileext = ".png")
ggsave(temp_, ggplot(data = data_slot) +
aes(x = Sepal.Length, y = Sepal.Width) +
geom_point())
temp_ <- knitr::image_uri(temp_)
data <- list(html_url = sprintf('<img src="%s">', temp_))
res$json(data)
})
app$start()Et si {shiny} n’existait pas ? | Retrouvez nous sur https://thinkr.fr
Comment se sortir de cette impasse ?
Retour d’experience d’un dev {shiny} dans un monde où {shiny} n’existe pas !